import React, { useReducer } from 'react';
import ReactDOM from 'react-dom';
let reducer = (state, action) => {
  switch (action.type) {
    case 'add':
      return {
        ...state,
        age: state.age + action.qqq
      }
    case 'minus':
      return {
        ...state,
        age: state.age - action.qqq
      }
    case 'changeName':
      return {
        ...state,
        name: action.na
      }
    default:
      return {
        ...state
      }
  }
}
function App() {
  let [state, dispatch] = useReducer(reducer, {
    name: "珠峰",
    age: 12
  })
  return <>
    <h1>{state.name}==={state.age}</h1>
    <button onClick={() => { dispatch({ type: 'add', qqq: 10 }) }}>+</button>
    <button onClick={() => { dispatch({ type: 'minus', qqq: 10 }) }}>-</button>
    <button onClick={() => { dispatch({ type: 'changeName', na: "珠峰666" }) }}>改名字</button>
  </>
}

ReactDOM.render(<App />, document.getElementById('root'))